<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <div id="app">
        <neu-button></neu-button>
        <neu-button></neu-button>
        <neu-button></neu-button>
        <my-component></my-component>
    </div>
    <hr>
    <div id="box">
        <neu-button></neu-button>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script>
        // 全局组件
        Vue.component('neu-button',{
            template : `<div><button @click="add">按钮被点击了 {{num}} 次</button></div>`,
            data(){
                return {
                    num : 0
                }
            },
            methods:{
                add(){
                    this.num++;
                }
            }
        })

        // 局部组件 - 注册
        let myComponent = {
            template : `<div><button @click="add">按钮被点击了 {{num}} 次</button></div>`,
            data(){
                return {
                    num : 100
                }
            },
            methods:{
                add(){
                    this.num++;
                }
            }
        };

        let vm = new Vue({
            el: '#app',
            data: {},
            methods: {},
            components :{ // 注册局部组件
                myComponent
            }
        });

        let vm2 = new Vue({
            el: '#box',
            data: {},
            methods: {}
        });
    </script>
</body>

</html>